package com.htandroid.htandroid.webservice;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;

import org.xmlpull.v1.XmlPullParser;


import android.util.Xml;

import com.htandroid.htandroid.entity.RdrecordAppList;

public class XMLKcapplist {

    /**
     * 解析评论xml信息
     *
     * @param result
     * @return
     */
    public static ArrayList<RdrecordAppList> paraseCommentInfors(String result) {
        ArrayList<RdrecordAppList> list = new ArrayList<RdrecordAppList>();
        //字符转换成字节流
        InputStream inputStream = new ByteArrayInputStream(result.getBytes());
        XmlPullParser parser = Xml.newPullParser();
        String aa = "";
        try {
            parser.setInput(inputStream, "UTF-8");
            int eventType = parser.getEventType();
            RdrecordAppList info = new RdrecordAppList();

            while (eventType != XmlPullParser.END_DOCUMENT) {
                switch (eventType) {
                    case XmlPullParser.START_DOCUMENT:// 文档开始事件,可以进行数据初始化处理
                        break;
                    case XmlPullParser.START_TAG:// 开始元素事件
                        String name = parser.getName();
                        if (name.equalsIgnoreCase("RdrecordAppList")) {
                            info = new RdrecordAppList();
                        } else {
                            eventType = parser.next();
                            if (name.equalsIgnoreCase("cvouchid")) {
                                info.setCvouchid(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cvouchtype")) {
                                info.setCvouchtype(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("ddate")) {
                                info.setDdate(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cwhcode")) {
                                info.setCwhcode(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cwhname")) {
                                info.setCwhname(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cdepcode")) {
                                info.setCdepcode(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cdepname")) {
                                info.setCdepname(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cirdcode")) {
                                info.setCirdcode(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cirdname")) {
                                info.setCirdname(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cordcode")) {
                                info.setCordcode(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cordname")) {
                                info.setCordname(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("ccuscode")) {
                                info.setCcuscode(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("ccusname")) {
                                info.setCcusname(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cvencode")) {
                                info.setCvencode(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cvenname")) {
                                info.setCvenname(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cdefine1")) {
                                info.setCdefine1(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cdefine2")) {
                                info.setCdefine2(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cdefine3")) {
                                info.setCdefine3(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cshdefine1")) {
                                info.setCshdefine1(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cshdefine2")) {
                                info.setCshdefine2(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cshdefine3")) {
                                info.setCshdefine3(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cshdefine4")) {
                                info.setCshdefine4(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cmaker")) {
                                info.setCmaker(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("chandler")) {
                                info.setChandler(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cmemo")) {
                                info.setCmemo(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("ccheckchar")) {
                                info.setCcheckchar(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cnocheckreason")) {
                                info.setCnocheckreason(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("linename")) {
                                info.setLinename(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cchar")) {
                                info.setCchar(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("al_inorder")) {
                                info.setAl_inorder(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("inorder")) {
                                info.setInorder(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cdepchecker")) {
                                info.setCdepchecker(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cmakedate")) {
                                info.setCmakedate(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cchecker")) {
                                info.setCchecker(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("ccheckdate")) {
                                info.setCcheckdate(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("resign")) {
                                info.setResign(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("isndjz")) {
                                info.setIsndjz(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("stepall")) {
                                info.setStepall(string2null(parser.getText()));
                            }
                        }
                        break;
                    case XmlPullParser.END_TAG:// 结束元素事件
                        if (parser.getName().equalsIgnoreCase("RdrecordAppList")) {
                            list.add(info);
                            info = null;
                        }
                        break;
                }
                eventType = parser.next();
                if (eventType == 3) {
                    if (aa.equals("")) {
                        aa = "1";
                    } else if (aa.equals("1")) {
                        aa = "2";
                    } else {
                        break;
                    }
                } else {
                    aa = "";
                }
            }
            inputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    //函数作用是把null 转为空
    public static String string2null(String str) {
        String rtn = "";
        if (str == null || str.equals("null") || str.equals("anyType{}")) {
            rtn = "";
        } else {
            rtn = str;
        }
        return rtn;
    }

}  
